package com.turnengine.client.local.location.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Coordinate.
 */
public class Coordinate implements ICoordinate, Comparable<ICoordinate> {

	/** The location id. */
	private int locationId = -1;
	/** The coordinates. */
	private int[] coordinates = null;

	/**
	 * Creates a new Coordinate.
	 */
	public Coordinate() {
	}

	/**
	 * Creates a new Coordinate.
	 * @param locationId the location id
	 * @param coordinates the coordinates
	 */
	public Coordinate(int locationId, int[] coordinates) {
		setLocationId(locationId);
		setCoordinates(coordinates);
	}

	/**
	 * Creates a new Coordinate.
	 * @param coordinate the coordinate
	 */
	public Coordinate(Coordinate coordinate) {
		setLocationId(coordinate.getLocationId());
		setCoordinates(coordinate.getCoordinates());
	}

	/**
	 * Creates a new Coordinate.
	 * @param iCoordinate the i coordinate
	 */
	public Coordinate(ICoordinate iCoordinate) {
		setLocationId(iCoordinate.getLocationId());
		setCoordinates(iCoordinate.getCoordinates());
	}

	/**
	 * Returns the location id.
	 * @return the location id.
	 */
	public int getLocationId() {
		return locationId;
	}

	/**
	 * Returns the coordinates.
	 * @return the coordinates.
	 */
	public int[] getCoordinates() {
		return coordinates;
	}

	/**
	 * Sets the location id.
	 * @param locationId the location id to set.
	 */
	public void setLocationId(int locationId) {
		this.locationId = locationId;
	}

	/**
	 * Sets the coordinates.
	 * @param coordinates the coordinates to set.
	 */
	public void setCoordinates(int[] coordinates) {
		this.coordinates = coordinates;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(677, 37);
		hash.append(locationId);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Coordinate) {
			Coordinate compare = (Coordinate) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.locationId, compare.locationId);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ICoordinate compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.locationId, compare.getLocationId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("locationId", locationId);
		if (coordinates != null) {
			string.append("coordinates", coordinates);
		}
		return string.toString();
	}
}
